//-----------------------------------------------------------------------
// <copyright file="a_SupplierDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_SupplierDAOBase
    {
        #region Common methods
        public virtual a_Supplier Createa_SupplierFromReader(IDataReader reader)
        {
            a_Supplier item = new a_Supplier();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("SupplierID"))) item.SupplierID = (int)reader["SupplierID"];
                if (!reader.IsDBNull(reader.GetOrdinal("UserID"))) item.UserID = (int)reader["UserID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SupplierType"))) item.SupplierType = (int)reader["SupplierType"];
                if (!reader.IsDBNull(reader.GetOrdinal("TradeType"))) item.TradeType = (byte)reader["TradeType"];
                if (!reader.IsDBNull(reader.GetOrdinal("IndustryiD"))) item.IndustryiD = (int)reader["IndustryiD"];
                if (!reader.IsDBNull(reader.GetOrdinal("BusinessName"))) item.BusinessName = (string)reader["BusinessName"];
                if (!reader.IsDBNull(reader.GetOrdinal("BusinessTypeID"))) item.BusinessTypeID = (int)reader["BusinessTypeID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CompanyPrefix"))) item.CompanyPrefix = (string)reader["CompanyPrefix"];
                if (!reader.IsDBNull(reader.GetOrdinal("CompanyName"))) item.CompanyName = (string)reader["CompanyName"];
                if (!reader.IsDBNull(reader.GetOrdinal("ExecFirstname"))) item.ExecFirstname = (string)reader["ExecFirstname"];
                if (!reader.IsDBNull(reader.GetOrdinal("ExecLastname"))) item.ExecLastname = (string)reader["ExecLastname"];
                if (!reader.IsDBNull(reader.GetOrdinal("ExecMiddlename"))) item.ExecMiddlename = (string)reader["ExecMiddlename"];
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) item.Address = (string)reader["Address"];
                if (!reader.IsDBNull(reader.GetOrdinal("District"))) item.District = (string)reader["District"];
                if (!reader.IsDBNull(reader.GetOrdinal("City"))) item.City = (string)reader["City"];
                if (!reader.IsDBNull(reader.GetOrdinal("VNCompanyPrefix"))) item.VNCompanyPrefix = (string)reader["VNCompanyPrefix"];
                if (!reader.IsDBNull(reader.GetOrdinal("VNCompanyName"))) item.VNCompanyName = (string)reader["VNCompanyName"];
                if (!reader.IsDBNull(reader.GetOrdinal("VNExecFirstname"))) item.VNExecFirstname = (string)reader["VNExecFirstname"];
                if (!reader.IsDBNull(reader.GetOrdinal("VNExecLastname"))) item.VNExecLastname = (string)reader["VNExecLastname"];
                if (!reader.IsDBNull(reader.GetOrdinal("VNExecMiddlename"))) item.VNExecMiddlename = (string)reader["VNExecMiddlename"];
                if (!reader.IsDBNull(reader.GetOrdinal("VNAddress"))) item.VNAddress = (string)reader["VNAddress"];
                if (!reader.IsDBNull(reader.GetOrdinal("VNDistrict"))) item.VNDistrict = (string)reader["VNDistrict"];
                if (!reader.IsDBNull(reader.GetOrdinal("VNCity"))) item.VNCity = (string)reader["VNCity"];
                if (!reader.IsDBNull(reader.GetOrdinal("Country"))) item.Country = (string)reader["Country"];
                if (!reader.IsDBNull(reader.GetOrdinal("State"))) item.State = (string)reader["State"];
                if (!reader.IsDBNull(reader.GetOrdinal("PostalCode"))) item.PostalCode = (string)reader["PostalCode"];
                if (!reader.IsDBNull(reader.GetOrdinal("Phone1CityCode"))) item.Phone1CityCode = (string)reader["Phone1CityCode"];
                if (!reader.IsDBNull(reader.GetOrdinal("Phone1Number"))) item.Phone1Number = (string)reader["Phone1Number"];
                if (!reader.IsDBNull(reader.GetOrdinal("Phone2CityCode"))) item.Phone2CityCode = (string)reader["Phone2CityCode"];
                if (!reader.IsDBNull(reader.GetOrdinal("Phone2Number"))) item.Phone2Number = (string)reader["Phone2Number"];
                if (!reader.IsDBNull(reader.GetOrdinal("FaxCityCode"))) item.FaxCityCode = (string)reader["FaxCityCode"];
                if (!reader.IsDBNull(reader.GetOrdinal("FaxNumber"))) item.FaxNumber = (string)reader["FaxNumber"];
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) item.Email = (string)reader["Email"];
                if (!reader.IsDBNull(reader.GetOrdinal("WebURL"))) item.WebURL = (string)reader["WebURL"];
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationForm"))) item.OrganizationForm = (int)reader["OrganizationForm"];
                if (!reader.IsDBNull(reader.GetOrdinal("MfgAreasM2"))) item.MfgAreasM2 = (int)reader["MfgAreasM2"];
                if (!reader.IsDBNull(reader.GetOrdinal("NumberOfEmployee"))) item.NumberOfEmployee = (int)reader["NumberOfEmployee"];
                if (!reader.IsDBNull(reader.GetOrdinal("OtherNotes"))) item.OtherNotes = (string)reader["OtherNotes"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatID"))) item.CatID = (int)reader["CatID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatName"))) item.CatName = (string)reader["CatName"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatID"))) item.SubCatID = (int)reader["SubCatID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatName"))) item.SubCatName = (string)reader["SubCatName"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2ID"))) item.SubCat2ID = (int)reader["SubCat2ID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2Name"))) item.SubCat2Name = (string)reader["SubCat2Name"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatID2"))) item.CatID2 = (int)reader["CatID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatName2"))) item.CatName2 = (string)reader["CatName2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatID2"))) item.SubCatID2 = (int)reader["SubCatID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatName2"))) item.SubCatName2 = (string)reader["SubCatName2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2ID2"))) item.SubCat2ID2 = (int)reader["SubCat2ID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2Name2"))) item.SubCat2Name2 = (string)reader["SubCat2Name2"];
                if (!reader.IsDBNull(reader.GetOrdinal("Market1"))) item.Market1 = (int)reader["Market1"];
                if (!reader.IsDBNull(reader.GetOrdinal("Market2"))) item.Market2 = (string)reader["Market2"];
                if (!reader.IsDBNull(reader.GetOrdinal("Contact"))) item.Contact = (string)reader["Contact"];
                if (!reader.IsDBNull(reader.GetOrdinal("AnualSale"))) item.AnualSale = (int)reader["AnualSale"];
                if (!reader.IsDBNull(reader.GetOrdinal("YearEst"))) item.YearEst = (int)reader["YearEst"];
                if (!reader.IsDBNull(reader.GetOrdinal("Certification"))) item.Certification = (string)reader["Certification"];
                if (!reader.IsDBNull(reader.GetOrdinal("JobID"))) item.JobID = (int)reader["JobID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Keyword1"))) item.Keyword1 = (string)reader["Keyword1"];
                if (!reader.IsDBNull(reader.GetOrdinal("Keyword2"))) item.Keyword2 = (string)reader["Keyword2"];
                if (!reader.IsDBNull(reader.GetOrdinal("Keyword3"))) item.Keyword3 = (string)reader["Keyword3"];
                if (!reader.IsDBNull(reader.GetOrdinal("CompanyIntro"))) item.CompanyIntro = (string)reader["CompanyIntro"];
                if (!reader.IsDBNull(reader.GetOrdinal("MainProducts"))) item.MainProducts = (string)reader["MainProducts"];
                if (!reader.IsDBNull(reader.GetOrdinal("Factory"))) item.Factory = (string)reader["Factory"];
                if (!reader.IsDBNull(reader.GetOrdinal("Machinery"))) item.Machinery = (string)reader["Machinery"];
                if (!reader.IsDBNull(reader.GetOrdinal("Capacity"))) item.Capacity = (string)reader["Capacity"];
                if (!reader.IsDBNull(reader.GetOrdinal("Turnover"))) item.Turnover = (string)reader["Turnover"];
                if (!reader.IsDBNull(reader.GetOrdinal("CapitalLegal"))) item.CapitalLegal = (string)reader["CapitalLegal"];
                if (!reader.IsDBNull(reader.GetOrdinal("CapitalJV"))) item.CapitalJV = (string)reader["CapitalJV"];
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNo"))) item.LicenseNo = (string)reader["LicenseNo"];
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseOversea"))) item.LicenseOversea = (string)reader["LicenseOversea"];
                if (!reader.IsDBNull(reader.GetOrdinal("TaxNo"))) item.TaxNo = (string)reader["TaxNo"];
                if (!reader.IsDBNull(reader.GetOrdinal("QualityControl"))) item.QualityControl = (string)reader["QualityControl"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("TargetQC"))) item.TargetQC = (string)reader["TargetQC"];
                if (!reader.IsDBNull(reader.GetOrdinal("RatingAvg"))) item.RatingAvg = (int)reader["RatingAvg"];
                if (!reader.IsDBNull(reader.GetOrdinal("RatingCount"))) item.RatingCount = (int)reader["RatingCount"];
                if (!reader.IsDBNull(reader.GetOrdinal("Equipment"))) item.Equipment = (int)reader["Equipment"];
                if (!reader.IsDBNull(reader.GetOrdinal("MajorClient"))) item.MajorClient = (string)reader["MajorClient"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsMajorClient"))) item.IsMajorClient = (bool)reader["IsMajorClient"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsActive"))) item.IsActive = (bool)reader["IsActive"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_Supplier methods
            
        public virtual void Createa_Supplier(a_Supplier a_Supplier)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Suppliers_ins");
                
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_Supplier.UserID);
                database.AddInParameter(dbCommand, "@SupplierType", DbType.Int32, a_Supplier.SupplierType);
                database.AddInParameter(dbCommand, "@TradeType", DbType.Byte, a_Supplier.TradeType);
                database.AddInParameter(dbCommand, "@IndustryiD", DbType.Int32, a_Supplier.IndustryiD);
                database.AddInParameter(dbCommand, "@BusinessName", DbType.String, a_Supplier.BusinessName);
                database.AddInParameter(dbCommand, "@BusinessTypeID", DbType.Int32, a_Supplier.BusinessTypeID);
                database.AddInParameter(dbCommand, "@CompanyPrefix", DbType.String, a_Supplier.CompanyPrefix);
                database.AddInParameter(dbCommand, "@CompanyName", DbType.String, a_Supplier.CompanyName);
                database.AddInParameter(dbCommand, "@ExecFirstname", DbType.String, a_Supplier.ExecFirstname);
                database.AddInParameter(dbCommand, "@ExecLastname", DbType.String, a_Supplier.ExecLastname);
                database.AddInParameter(dbCommand, "@ExecMiddlename", DbType.String, a_Supplier.ExecMiddlename);
                database.AddInParameter(dbCommand, "@Address", DbType.String, a_Supplier.Address);
                database.AddInParameter(dbCommand, "@District", DbType.String, a_Supplier.District);
                database.AddInParameter(dbCommand, "@City", DbType.String, a_Supplier.City);
                database.AddInParameter(dbCommand, "@VNCompanyPrefix", DbType.String, a_Supplier.VNCompanyPrefix);
                database.AddInParameter(dbCommand, "@VNCompanyName", DbType.String, a_Supplier.VNCompanyName);
                database.AddInParameter(dbCommand, "@VNExecFirstname", DbType.String, a_Supplier.VNExecFirstname);
                database.AddInParameter(dbCommand, "@VNExecLastname", DbType.String, a_Supplier.VNExecLastname);
                database.AddInParameter(dbCommand, "@VNExecMiddlename", DbType.String, a_Supplier.VNExecMiddlename);
                database.AddInParameter(dbCommand, "@VNAddress", DbType.String, a_Supplier.VNAddress);
                database.AddInParameter(dbCommand, "@VNDistrict", DbType.String, a_Supplier.VNDistrict);
                database.AddInParameter(dbCommand, "@VNCity", DbType.String, a_Supplier.VNCity);
                database.AddInParameter(dbCommand, "@Country", DbType.AnsiStringFixedLength, a_Supplier.Country);
                database.AddInParameter(dbCommand, "@State", DbType.String, a_Supplier.State);
                database.AddInParameter(dbCommand, "@PostalCode", DbType.String, a_Supplier.PostalCode);
                database.AddInParameter(dbCommand, "@Phone1CityCode", DbType.String, a_Supplier.Phone1CityCode);
                database.AddInParameter(dbCommand, "@Phone1Number", DbType.String, a_Supplier.Phone1Number);
                database.AddInParameter(dbCommand, "@Phone2CityCode", DbType.String, a_Supplier.Phone2CityCode);
                database.AddInParameter(dbCommand, "@Phone2Number", DbType.String, a_Supplier.Phone2Number);
                database.AddInParameter(dbCommand, "@FaxCityCode", DbType.String, a_Supplier.FaxCityCode);
                database.AddInParameter(dbCommand, "@FaxNumber", DbType.String, a_Supplier.FaxNumber);
                database.AddInParameter(dbCommand, "@Email", DbType.String, a_Supplier.Email);
                database.AddInParameter(dbCommand, "@WebURL", DbType.String, a_Supplier.WebURL);
                database.AddInParameter(dbCommand, "@OrganizationForm", DbType.Int32, a_Supplier.OrganizationForm);
                database.AddInParameter(dbCommand, "@MfgAreasM2", DbType.Int32, a_Supplier.MfgAreasM2);
                database.AddInParameter(dbCommand, "@NumberOfEmployee", DbType.Int32, a_Supplier.NumberOfEmployee);
                database.AddInParameter(dbCommand, "@OtherNotes", DbType.String, a_Supplier.OtherNotes);
                database.AddInParameter(dbCommand, "@CatID", DbType.Int32, a_Supplier.CatID);
                database.AddInParameter(dbCommand, "@CatName", DbType.String, a_Supplier.CatName);
                database.AddInParameter(dbCommand, "@SubCatID", DbType.Int32, a_Supplier.SubCatID);
                database.AddInParameter(dbCommand, "@SubCatName", DbType.String, a_Supplier.SubCatName);
                database.AddInParameter(dbCommand, "@SubCat2ID", DbType.Int32, a_Supplier.SubCat2ID);
                database.AddInParameter(dbCommand, "@SubCat2Name", DbType.String, a_Supplier.SubCat2Name);
                database.AddInParameter(dbCommand, "@CatID2", DbType.Int32, a_Supplier.CatID2);
                database.AddInParameter(dbCommand, "@CatName2", DbType.String, a_Supplier.CatName2);
                database.AddInParameter(dbCommand, "@SubCatID2", DbType.Int32, a_Supplier.SubCatID2);
                database.AddInParameter(dbCommand, "@SubCatName2", DbType.String, a_Supplier.SubCatName2);
                database.AddInParameter(dbCommand, "@SubCat2ID2", DbType.Int32, a_Supplier.SubCat2ID2);
                database.AddInParameter(dbCommand, "@SubCat2Name2", DbType.String, a_Supplier.SubCat2Name2);
                database.AddInParameter(dbCommand, "@Market1", DbType.Int32, a_Supplier.Market1);
                database.AddInParameter(dbCommand, "@Market2", DbType.String, a_Supplier.Market2);
                database.AddInParameter(dbCommand, "@Contact", DbType.String, a_Supplier.Contact);
                database.AddInParameter(dbCommand, "@AnualSale", DbType.Int32, a_Supplier.AnualSale);
                database.AddInParameter(dbCommand, "@YearEst", DbType.Int32, a_Supplier.YearEst);
                database.AddInParameter(dbCommand, "@Certification", DbType.String, a_Supplier.Certification);
                database.AddInParameter(dbCommand, "@JobID", DbType.Int32, a_Supplier.JobID);
                database.AddInParameter(dbCommand, "@Keyword1", DbType.AnsiString, a_Supplier.Keyword1);
                database.AddInParameter(dbCommand, "@Keyword2", DbType.AnsiString, a_Supplier.Keyword2);
                database.AddInParameter(dbCommand, "@Keyword3", DbType.AnsiString, a_Supplier.Keyword3);
                database.AddInParameter(dbCommand, "@CompanyIntro", DbType.String, a_Supplier.CompanyIntro);
                database.AddInParameter(dbCommand, "@MainProducts", DbType.String, a_Supplier.MainProducts);
                database.AddInParameter(dbCommand, "@Factory", DbType.String, a_Supplier.Factory);
                database.AddInParameter(dbCommand, "@Machinery", DbType.String, a_Supplier.Machinery);
                database.AddInParameter(dbCommand, "@Capacity", DbType.String, a_Supplier.Capacity);
                database.AddInParameter(dbCommand, "@Turnover", DbType.String, a_Supplier.Turnover);
                database.AddInParameter(dbCommand, "@CapitalLegal", DbType.String, a_Supplier.CapitalLegal);
                database.AddInParameter(dbCommand, "@CapitalJV", DbType.String, a_Supplier.CapitalJV);
                database.AddInParameter(dbCommand, "@LicenseNo", DbType.String, a_Supplier.LicenseNo);
                database.AddInParameter(dbCommand, "@LicenseOversea", DbType.String, a_Supplier.LicenseOversea);
                database.AddInParameter(dbCommand, "@TaxNo", DbType.String, a_Supplier.TaxNo);
                database.AddInParameter(dbCommand, "@QualityControl", DbType.String, a_Supplier.QualityControl);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_Supplier.DomainID);
                database.AddInParameter(dbCommand, "@TargetQC", DbType.String, a_Supplier.TargetQC);
                database.AddInParameter(dbCommand, "@RatingAvg", DbType.Int32, a_Supplier.RatingAvg);
                database.AddInParameter(dbCommand, "@RatingCount", DbType.Int32, a_Supplier.RatingCount);
                database.AddInParameter(dbCommand, "@Equipment", DbType.Int32, a_Supplier.Equipment);
                database.AddInParameter(dbCommand, "@MajorClient", DbType.String, a_Supplier.MajorClient);
                database.AddInParameter(dbCommand, "@IsMajorClient", DbType.Boolean, a_Supplier.IsMajorClient);
                database.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, a_Supplier.IsActive);
                database.AddOutParameter(dbCommand, "@SupplierID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_Supplier.SupplierID = (int)database.GetParameterValue(dbCommand, "@SupplierID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_Supplier methods
        
        public virtual void Updatea_Supplier(a_Supplier a_Supplier)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Suppliers_upd");            
                
                database.AddInParameter(dbCommand, "@SupplierID", DbType.Int32, a_Supplier.SupplierID);
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_Supplier.UserID);
                database.AddInParameter(dbCommand, "@SupplierType", DbType.Int32, a_Supplier.SupplierType);
                database.AddInParameter(dbCommand, "@TradeType", DbType.Byte, a_Supplier.TradeType);
                database.AddInParameter(dbCommand, "@IndustryiD", DbType.Int32, a_Supplier.IndustryiD);
                database.AddInParameter(dbCommand, "@BusinessName", DbType.String, a_Supplier.BusinessName);
                database.AddInParameter(dbCommand, "@BusinessTypeID", DbType.Int32, a_Supplier.BusinessTypeID);
                database.AddInParameter(dbCommand, "@CompanyPrefix", DbType.String, a_Supplier.CompanyPrefix);
                database.AddInParameter(dbCommand, "@CompanyName", DbType.String, a_Supplier.CompanyName);
                database.AddInParameter(dbCommand, "@ExecFirstname", DbType.String, a_Supplier.ExecFirstname);
                database.AddInParameter(dbCommand, "@ExecLastname", DbType.String, a_Supplier.ExecLastname);
                database.AddInParameter(dbCommand, "@ExecMiddlename", DbType.String, a_Supplier.ExecMiddlename);
                database.AddInParameter(dbCommand, "@Address", DbType.String, a_Supplier.Address);
                database.AddInParameter(dbCommand, "@District", DbType.String, a_Supplier.District);
                database.AddInParameter(dbCommand, "@City", DbType.String, a_Supplier.City);
                database.AddInParameter(dbCommand, "@VNCompanyPrefix", DbType.String, a_Supplier.VNCompanyPrefix);
                database.AddInParameter(dbCommand, "@VNCompanyName", DbType.String, a_Supplier.VNCompanyName);
                database.AddInParameter(dbCommand, "@VNExecFirstname", DbType.String, a_Supplier.VNExecFirstname);
                database.AddInParameter(dbCommand, "@VNExecLastname", DbType.String, a_Supplier.VNExecLastname);
                database.AddInParameter(dbCommand, "@VNExecMiddlename", DbType.String, a_Supplier.VNExecMiddlename);
                database.AddInParameter(dbCommand, "@VNAddress", DbType.String, a_Supplier.VNAddress);
                database.AddInParameter(dbCommand, "@VNDistrict", DbType.String, a_Supplier.VNDistrict);
                database.AddInParameter(dbCommand, "@VNCity", DbType.String, a_Supplier.VNCity);
                database.AddInParameter(dbCommand, "@Country", DbType.AnsiStringFixedLength, a_Supplier.Country);
                database.AddInParameter(dbCommand, "@State", DbType.String, a_Supplier.State);
                database.AddInParameter(dbCommand, "@PostalCode", DbType.String, a_Supplier.PostalCode);
                database.AddInParameter(dbCommand, "@Phone1CityCode", DbType.String, a_Supplier.Phone1CityCode);
                database.AddInParameter(dbCommand, "@Phone1Number", DbType.String, a_Supplier.Phone1Number);
                database.AddInParameter(dbCommand, "@Phone2CityCode", DbType.String, a_Supplier.Phone2CityCode);
                database.AddInParameter(dbCommand, "@Phone2Number", DbType.String, a_Supplier.Phone2Number);
                database.AddInParameter(dbCommand, "@FaxCityCode", DbType.String, a_Supplier.FaxCityCode);
                database.AddInParameter(dbCommand, "@FaxNumber", DbType.String, a_Supplier.FaxNumber);
                database.AddInParameter(dbCommand, "@Email", DbType.String, a_Supplier.Email);
                database.AddInParameter(dbCommand, "@WebURL", DbType.String, a_Supplier.WebURL);
                database.AddInParameter(dbCommand, "@OrganizationForm", DbType.Int32, a_Supplier.OrganizationForm);
                database.AddInParameter(dbCommand, "@MfgAreasM2", DbType.Int32, a_Supplier.MfgAreasM2);
                database.AddInParameter(dbCommand, "@NumberOfEmployee", DbType.Int32, a_Supplier.NumberOfEmployee);
                database.AddInParameter(dbCommand, "@OtherNotes", DbType.String, a_Supplier.OtherNotes);
                database.AddInParameter(dbCommand, "@CatID", DbType.Int32, a_Supplier.CatID);
                database.AddInParameter(dbCommand, "@CatName", DbType.String, a_Supplier.CatName);
                database.AddInParameter(dbCommand, "@SubCatID", DbType.Int32, a_Supplier.SubCatID);
                database.AddInParameter(dbCommand, "@SubCatName", DbType.String, a_Supplier.SubCatName);
                database.AddInParameter(dbCommand, "@SubCat2ID", DbType.Int32, a_Supplier.SubCat2ID);
                database.AddInParameter(dbCommand, "@SubCat2Name", DbType.String, a_Supplier.SubCat2Name);
                database.AddInParameter(dbCommand, "@CatID2", DbType.Int32, a_Supplier.CatID2);
                database.AddInParameter(dbCommand, "@CatName2", DbType.String, a_Supplier.CatName2);
                database.AddInParameter(dbCommand, "@SubCatID2", DbType.Int32, a_Supplier.SubCatID2);
                database.AddInParameter(dbCommand, "@SubCatName2", DbType.String, a_Supplier.SubCatName2);
                database.AddInParameter(dbCommand, "@SubCat2ID2", DbType.Int32, a_Supplier.SubCat2ID2);
                database.AddInParameter(dbCommand, "@SubCat2Name2", DbType.String, a_Supplier.SubCat2Name2);
                database.AddInParameter(dbCommand, "@Market1", DbType.Int32, a_Supplier.Market1);
                database.AddInParameter(dbCommand, "@Market2", DbType.String, a_Supplier.Market2);
                database.AddInParameter(dbCommand, "@Contact", DbType.String, a_Supplier.Contact);
                database.AddInParameter(dbCommand, "@AnualSale", DbType.Int32, a_Supplier.AnualSale);
                database.AddInParameter(dbCommand, "@YearEst", DbType.Int32, a_Supplier.YearEst);
                database.AddInParameter(dbCommand, "@Certification", DbType.String, a_Supplier.Certification);
                database.AddInParameter(dbCommand, "@JobID", DbType.Int32, a_Supplier.JobID);
                database.AddInParameter(dbCommand, "@Keyword1", DbType.AnsiString, a_Supplier.Keyword1);
                database.AddInParameter(dbCommand, "@Keyword2", DbType.AnsiString, a_Supplier.Keyword2);
                database.AddInParameter(dbCommand, "@Keyword3", DbType.AnsiString, a_Supplier.Keyword3);
                database.AddInParameter(dbCommand, "@CompanyIntro", DbType.String, a_Supplier.CompanyIntro);
                database.AddInParameter(dbCommand, "@MainProducts", DbType.String, a_Supplier.MainProducts);
                database.AddInParameter(dbCommand, "@Factory", DbType.String, a_Supplier.Factory);
                database.AddInParameter(dbCommand, "@Machinery", DbType.String, a_Supplier.Machinery);
                database.AddInParameter(dbCommand, "@Capacity", DbType.String, a_Supplier.Capacity);
                database.AddInParameter(dbCommand, "@Turnover", DbType.String, a_Supplier.Turnover);
                database.AddInParameter(dbCommand, "@CapitalLegal", DbType.String, a_Supplier.CapitalLegal);
                database.AddInParameter(dbCommand, "@CapitalJV", DbType.String, a_Supplier.CapitalJV);
                database.AddInParameter(dbCommand, "@LicenseNo", DbType.String, a_Supplier.LicenseNo);
                database.AddInParameter(dbCommand, "@LicenseOversea", DbType.String, a_Supplier.LicenseOversea);
                database.AddInParameter(dbCommand, "@TaxNo", DbType.String, a_Supplier.TaxNo);
                database.AddInParameter(dbCommand, "@QualityControl", DbType.String, a_Supplier.QualityControl);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_Supplier.DomainID);
                database.AddInParameter(dbCommand, "@TargetQC", DbType.String, a_Supplier.TargetQC);
                database.AddInParameter(dbCommand, "@RatingAvg", DbType.Int32, a_Supplier.RatingAvg);
                database.AddInParameter(dbCommand, "@RatingCount", DbType.Int32, a_Supplier.RatingCount);
                database.AddInParameter(dbCommand, "@Equipment", DbType.Int32, a_Supplier.Equipment);
                database.AddInParameter(dbCommand, "@MajorClient", DbType.String, a_Supplier.MajorClient);
                database.AddInParameter(dbCommand, "@IsMajorClient", DbType.Boolean, a_Supplier.IsMajorClient);
                database.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, a_Supplier.IsActive);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_Supplier methods
        public virtual void Deletea_Supplier(int supplierID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Suppliers_del");
                
                database.AddInParameter(dbCommand, "@SupplierID", DbType.Int32, supplierID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_Supplier methods
        
        public virtual a_Supplier Geta_Supplier(int supplierID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Suppliers_sel");
                
                database.AddInParameter(dbCommand, "@SupplierID", DbType.Int32, supplierID);
                
                a_Supplier a_Supplier =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_Supplier = Createa_SupplierFromReader(reader);
                        reader.Close();
                    }
                }
                return a_Supplier;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_SupplierList methods
        public virtual a_SupplierCollection Geta_SupplierList(a_SupplierColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Suppliers_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_SupplierCollection a_SupplierCollection = new a_SupplierCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_Supplier a_Supplier = Createa_SupplierFromReader(reader);
                        a_SupplierCollection.Add(a_Supplier);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_SupplierCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_SupplierCollection Geta_SupplierList(a_SupplierColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_SupplierList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}